<template>
    <div class="lesson_status">
        <x-header :left-options="{backText: ''}" >三会一课
          <a slot="right" to="" class="choose" :class="{'hide': $route.query.status == 'dynamic'}" @click="changChoose()"></a>
        </x-header>
        <div class="lesson_list">
          <div class="tab">
              <tab :line-width=2 active-color='rgb(214,60,50)' v-model="index">
                  <tab-item class="vux-center" :selected="selected === item" v-for="(item, index) in list" @on-item-click="handler(item)" :key="index">{{item}}</tab-item>
              </tab>
          </div>
          <router-view></router-view>
        </div>
    </div>
</template>

<script>
import { XHeader, Tab, TabItem } from "vux";
import { mapState, mapGetters } from "vuex";

const list = () => ["最新动态", "统计分析"];
export default {
  components: {
    XHeader,
    Tab,
    TabItem
  },
  computed: {
    ...mapGetters(["lessonPopup"])
  },
  data() {
    return {
      list: list(),
      index: 0,
      selected: ""
    };
  },
  watch: {
    $route(to, from) {
      if (to.query.status == "dynamic") {
        this.selected = "最新动态";
      }
    }
  },
  created() {
    let currentSelected = this.$route.query.status;
    if (currentSelected === "dynamic") {
      this.selected = "最新动态";
    } else if (currentSelected === "statistics") {
      this.selected = "统计分析";
    }
  },
  methods: {
    handler(item) {
      this.selected = item;
      let path = this.$route.path;
      if (item === "最新动态") {
        this.$router.replace(`${path}?status=dynamic`);
      } else if (item === "统计分析") {
        this.$router.replace(`${path}?status=statistics`);
      }
    },
    changChoose() {
      this.$store.dispatch("updateLessonPopup", {
        lessonPopup: true
      });
    }
  }
};
</script>

<style lang="less">
.lesson_status {
  font-size: 0;
  height: 100%;
  background: rgb(245, 245, 249);
  .choose {
    width: 1.375rem;
    height: 1.375rem;
    background: url("./shaixuan.png") no-repeat;
    background-size: 1.375rem 1.375rem;
  }
  .lesson_list{
    padding: 2.875rem 0 0;
    height: 100%;
  }
  .tab {
    position: fixed;
    z-index: 10;
    width: 100%;
  }
  .vux-tab {
    .vux-tab-item {
      font-size: 1.1875rem;
      color: rgb(0, 0, 0);
    }
  }
}
</style>